package com.yunmang.activity;

import android.graphics.Color;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.yunmang.R;
import com.yunmang.adapter.MyPagerAdapter;
import com.yunmang.fragment.BaseFragment;
import com.yunmang.fragment.HomePageFragment;
import com.yunmang.fragment.SettingFragment;
import com.yunmang.fragment.ServiceFragment;
import com.yunmang.fragment.StatementFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者 : bean on 2017/4/5/0005.
 * 注释 :
 */
public class HomeActivity extends BaseActivity {
    private RadioButton rb1;
    private RadioButton rb2;
    private RadioButton rb3;
    private RadioButton rb4;
    private ViewPager viewPager;
    private List<BaseFragment> fragments = new ArrayList<>();
    private RadioGroup rg_home_navigation;

    @Override
    public int getLayoutId() {
        return R.layout.activity_home;
    }

    @Override
    public void initView() {
        rg_home_navigation = (RadioGroup) findViewById(R.id.rg_home_navigation);
        rb1 = (RadioButton) findViewById(R.id.rb_1);
        rb2 = (RadioButton) findViewById(R.id.rb_2);
        rb3 = (RadioButton) findViewById(R.id.rb_3);
        rb4 = (RadioButton) findViewById(R.id.rb_4);
        viewPager = (ViewPager) findViewById(R.id.ll);
    }

    @Override
    public void initData() {
        fragments.add(new HomePageFragment());
        fragments.add(new ServiceFragment());
        fragments.add(new StatementFragment());
        fragments.add(new SettingFragment());
        viewPager.setAdapter(new MyPagerAdapter(getSupportFragmentManager(), fragments));
        viewPager.setCurrentItem(0);
        setBackgroundColors(rb1, 1);
    }

    @Override
    public void dealCommon() {
        super.dealCommon();
        rb1.setOnClickListener(this);
        rb2.setOnClickListener(this);
        rb3.setOnClickListener(this);
        rb4.setOnClickListener(this);
    }

    @Override
    public void onInnerClick(View v) {
        super.onInnerClick(v);
        switch (v.getId()) {

            case R.id.rb_1:
                viewPager.setCurrentItem(0);
                setBackgroundColors(rb1, 1);

                break;
            case R.id.rb_2:
                viewPager.setCurrentItem(1);
                setBackgroundColors(rb2, 2);
                break;
            case R.id.rb_3:
                viewPager.setCurrentItem(2);
                setBackgroundColors(rb3, 3);
                break;
            case R.id.rb_4:
                viewPager.setCurrentItem(3);
                setBackgroundColors(rb4, 4);
                break;
            default:
                break;
        }

    }

    private void setBackgroundColors(RadioButton rb, int count) {
        rb.setTextColor(Color.WHITE);
        rb.setBackgroundColor(Color.BLUE);
        if (count == 1) {
            rb2.setBackgroundColor(Color.WHITE);
            rb3.setBackgroundColor(Color.WHITE);
            rb4.setBackgroundColor(Color.WHITE);
            rb2.setTextColor(Color.BLACK);
            rb3.setTextColor(Color.BLACK);
            rb4.setTextColor(Color.BLACK);
        } else if (count == 2) {
            rb1.setBackgroundColor(Color.WHITE);
            rb3.setBackgroundColor(Color.WHITE);
            rb4.setBackgroundColor(Color.WHITE);
            rb1.setTextColor(Color.BLACK);
            rb3.setTextColor(Color.BLACK);
            rb4.setTextColor(Color.BLACK);
        } else if (count == 3) {
            rb1.setBackgroundColor(Color.WHITE);
            rb2.setBackgroundColor(Color.WHITE);
            rb4.setBackgroundColor(Color.WHITE);
            rb2.setTextColor(Color.BLACK);
            rb1.setTextColor(Color.BLACK);
            rb4.setTextColor(Color.BLACK);
        } else if (count == 4) {
            rb1.setBackgroundColor(Color.WHITE);
            rb2.setBackgroundColor(Color.WHITE);
            rb3.setBackgroundColor(Color.WHITE);
            rb1.setTextColor(Color.BLACK);
            rb3.setTextColor(Color.BLACK);
            rb2.setTextColor(Color.BLACK);
        }


    }

}